
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;




import javax.imageio.ImageIO;


class ButtonPressed extends Thread{
		ImageEditor parent;
		EditedImage[] images;
		File[] imgFile;
		SyncFlag flag;
		String loaded = "Loading images 0/0";
		boolean done = false;
		
		ButtonPressed(ImageEditor parent, SyncFlag sFlag, File[] files) {
			this.parent = parent;
			this.flag = sFlag;
			this.imgFile = files;
			}		
		
//		Timer timer = new Timer();
//		Toolkit toolkit;
//		
//		public void ReminderBeep() {
//			toolkit = Toolkit.getDefaultToolkit();
//			timer = new Timer();
//			timer.schedule(new RemindTask(), 150);
//			}
//		
//		class RemindTask extends TimerTask {
//			public void run() {
//				//System.out.println("Time's up!");
//				flag.get("Button");
//				timer.schedule(new RemindTask(), 150);
//			    //toolkit.beep();
//			    //timer.cancel(); //Not necessary because we call System.exit
//			    //System.exit(0); //Stops the AWT thread (and everything else)
//				}
//			}
		
        public void browse() {
        		//this.ReminderBeep();
                images = new EditedImage[imgFile.length];
                this.loaded = "Loading images 0/" + imgFile.length + "";
                
                for (int i=0; i< imgFile.length; i++) {
                	BufferedImage buff;
					try {
						this.loaded = "Loading images " + (i+1) + "/" + imgFile.length;
						buff = ImageIO.read(imgFile[i]);
						String name = imgFile[i].getName();
						String[] split = name.split("\\.");
						
						images[i] = new EditedImage(buff, this.parent.resizedDimension, split[1], split[0], imgFile[i].getPath());
						this.flag.get("Button");
						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}                	
                }
                
            this.done = true;
            flag.release();
            
        }

		@Override
		public void run() {
			this.browse();
			flag.release();
			
		}
    }
